package school.dao;

import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;

import util.DBUtil;
import java.sql.Types;

public class MetaData {

	public static void main(String[] args) throws Exception {
		Connection con = DBUtil.getConnection();
		DatabaseMetaData cm = con.getMetaData();
		System.out.println(cm.getDatabaseProductName() + ">"
				+ cm.getDatabaseProductVersion() + ">" + cm.getDriverName());
		System.out.println("是否支持事务：" + cm.supportsTransactions());
		String sql = "select * from student";
		PreparedStatement ps = con.prepareStatement(sql);
		ResultSet rs = ps.executeQuery();
		ResultSetMetaData rm = rs.getMetaData();
		System.out.println("这个*代表的列数：" + rm.getColumnCount());
		for (int i = 1; i <= rm.getColumnCount(); i++) {
			System.out.println(rm.getColumnLabel(i) + ","
					+ rm.getColumnTypeName(i) + ",对应的java类型："
					+ rm.getColumnClassName(i));
		}
		DBUtil.close(rs);
		DBUtil.close(ps);
		DBUtil.close(con);
	}

}
